package com.example.statisticsservice.schedule;

import com.example.statisticsservice.service.OrderStatisticsService;
import com.example.statisticsservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTask {
    @Autowired
    private OrderStatisticsService statisticsService;
    //在每天凌晨一点执行方法
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){
        //生成前一天的数据
        String date = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsService.createData(date);
    }
}
